package cn.zhqr.core.component;


import com.jfinal.plugin.redis.Cache;

import java.util.concurrent.ConcurrentHashMap;

public class UserInfoKit {

    private static final ConcurrentHashMap<Class,UserInfoManager> cacheManagerPool = new ConcurrentHashMap();


    public static void addManager(Class clazz, UserInfoManager userInfoManager) {
        if (clazz == null) {
            throw new IllegalArgumentException("The clazz can not be null");
        } else if (cacheManagerPool.containsKey(clazz)) {
            throw new IllegalArgumentException("The userInfoManager of class:"+clazz.getName()+" already exists");
        } else {
            cacheManagerPool.put(clazz, userInfoManager);
        }
    }

    public static Cache removeManager(Class clazz) {
        return (Cache) cacheManagerPool.remove(clazz);
    }

    public static UserInfoManager getManager(Class clazz) {
        return cacheManagerPool.get(clazz);
    }
}
